package com.wg.photo.activity;

import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.Button;


import com.wg.photo.BaseActivity;
import com.wg.photo.PictureView;
import com.wg.photo.R;
import com.wg.photo.utils.PickConfig;
import com.wg.photo.utils.PickPreferences;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends BaseActivity {
    private static final String TAG = "MainActivity";
    private Button mBtnChoose;
    private List<String> mPath = new ArrayList<>();

    @Override
    public int getLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    public void initViews() {
        mBtnChoose = (Button) findViewById(R.id.main_Btn_choose);
    }

    @Override
    public void setListeners() {
        mBtnChoose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new PictureView.Builder(MainActivity.this).start();
            }
        });
    }


    @Override
    protected void onDestroy() {
        PickPreferences.getInstance(this).clear();
        super.onDestroy();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == PickConfig.LIST_PICTURE_DATA){
            if (resultCode == RESULT_OK){
                List<String> paths = (List<String>) data.getSerializableExtra(PickConfig.INTENT_PICTURE_DATA);
                for (int i = 0; i < paths.size(); i++) {
                    Log.e(TAG, "onActivityResult: "+paths.get(i));
                }

               /* List<String> compPath = new ArrayList<>();
                List<String> selectPath = (List<String>) data.getSerializableExtra(PickConfig.INTENT_PICTURE_DATA);
                for (int i = 0; i < selectPath.size(); i++) {
                    File file = new File(selectPath.get(i));
                    String s = FileUtil.saveBitmapFile(file,Environment.getExternalStorageDirectory()+"/"+ getPackageName() + "/imge", file.getName());
                    compPath.add(s);
                }
                Log.e(TAG, "onActivityResult: "+compPath );*/
            }
        }
    }
}
